package vip.mall.modular.login.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.mall.common.exception.CommonException;
import vip.mall.common.result.CommonResult;
import vip.mall.modular.login.params.LoginParam;
import vip.mall.modular.login.service.LoginService;

/**
 * @author ASUS
 * @Date 2025/2/10 9:26
 * @Descripition 登录模块控制器
 */
@Tag(name = "登录模块控制器")
@RestController
@RequestMapping("/sys")
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/customerLogin")
    @Operation(summary = "普通用户登录")
    public CommonResult customerLogin(@RequestBody @Validated LoginParam loginParam) throws CommonException {
        return loginService.customerLogin(loginParam) ? CommonResult.success() : CommonResult.error("登录失败，用户名或密码错误");
    }

    @PostMapping("/adminLogin")
    @Operation(summary = "管理员用户登录")
    public CommonResult adminLogin(@RequestBody LoginParam loginParam) throws CommonException {
        return loginService.adminLogin(loginParam) ? CommonResult.success() : CommonResult.error("登录失败，用户名或密码错误");
    }
}
